<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>修改角色</legend>
</fieldset>
<div class="layui-form-item">
    <div class="layui-inline" >
        <form class="layui-form"  lay-filter="example"  >
            <input type="text" id="id" name="id" style="display: none" class="layui-input">
            <div class="layui-form-item">
                <label class="layui-form-label">角色标识</label>
                <div class="layui-input-inline">
                    <input type="text" id="name" name="name" lay-verify="name|required"  readonly  placeholder="角色标识" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">注释</label>
                <div class="layui-input-inline">
                    <input type="text" name="description" id="description" lay-verify="required"  placeholder="注释" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="button" class="layui-btn" lay-submit lay-filter="roleForm">保存修改</button>
                </div>
            </div>
        </form>
    </div>
</div>
<script  src="../../../layui/layui.js" ></script>
<script src="../../../layui/layui.all.js"  ></script>
<script src="../../../js/jquery.min.js"></script>
<script src="../../../js/common.js"></script>
<script>
    layui.use('table', function() {
        var form = layui.form;
        var layer = layui.layer;
        var roleId =getUrlParam("roleId");
         $(function(){
             $.ajax({
                 url:"/sysRole/findById?roleId="+roleId,
                 method:"post",
                 success:function(data){
                     form.val('example', {
                         "id": roleId // "name": "value"
                         ,"name": data.data.name
                         ,"description": data.data.description
                     });
                 }
             });
         })

        form.verify({
            name: function(value){
                if(!(/^[a-z]+$/i.test(value))){
                    return '只能为英文';
                }
            }
        });

             //监听提交
             form.on('submit(roleForm)', function(data){
                 $.ajax({
                     url:"/sysRole/saveRole",
                     method:"post",
                     data:data.field,
                     success:function(data){
                         if(data.code== 404 ){
                             layer.msg(data.msg);
                         }else {
                             layer.msg(data.msg);
                             setTimeout(function(){
                                 layer.close(layer.index);
                                 window.parent.location.reload();
                             },1800 );

                         }
                     }
                 });
             });
         })

</script>
</body>
</html>